package com.distributed.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.mina.util.Base64;

public final class Encryptor {
	public static String MD5Encrytor(String data) {
		MessageDigest md5 = null;
		try {
			md5 = MessageDigest.getInstance("MD5");
			md5.update(data.getBytes());
			byte[] bytes = md5.digest();
			if (bytes == null) {
				return null;
			}
			byte[] base64bytes = Base64.encodeBase64(bytes);
			return new String(base64bytes);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static String SHAEntrytor(String data) {
		MessageDigest sha = null;
		try {
			sha = MessageDigest.getInstance("SHA");
			sha.update(data.getBytes());
			byte[] bytes = sha.digest();
			if (bytes == null) {
				return null;
			}
			byte[] base64bytes = Base64.encodeBase64(bytes);
			return new String(base64bytes);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return null;
	}
}
